Selenium 2 - Submitting pin to roadpolice.am


In [1]:
from selenium import webdriver
browser = webdriver.Chrome()
url = "https://offense.roadpolice.am/violation"
browser.get(url)

In [2]:
pin_code = "173679JNYEJM"

In [3]:
input_form = browser.find_element_by_xpath('//*[@id="pin"]')
input_form.send_keys(pin_code)
submit_button = browser.find_element_by_tag_name("button")
submit_button.click()

In [8]:
js = '''html = document.getElementsByTagName('html')[0];
            return html.outerHTML;'''
html = browser.execute_script(js).encode('utf-8')

In [9]:
with open("page_source.html","w") as f:
    f.write(html)

In [11]:
with open("page_source.html","w") as f:
    f.write(browser.page_source.encode('utf-8'))

In [12]:
date = browser.find_element_by_xpath('//*[@id="main_data"]/tbody/tr[6]/td[3]')
print(date.text)


11 հնս. 2017թ. Ժամը` 10:31

In [13]:
amount = browser.find_element_by_css_selector("li b").text
print(amount)


5000 (հինգ հազար) դրամ (Վճարել առցանց):

In [14]:
import re

In [15]:
drams = re.findall("[0-9]+",amount)
print(drams[0])


5000

In [16]:
browser.close()